<?php
namespace app\api\controller;

use think\Request;

class Home extends BaseController
{
    public function roomList()
    {
        $data = [];

        if (Request::instance()->isPost()) {
            $user_id = input('post.user_id');
            $per_page = 20;
            $page = input('post.page');

            $room_model = model('Room');

            $join = [
                ['__BUILD__ b', 'r.build_id = b.build_id']
            ];

            $field = [
                'r.*',
                'b.build_address'
            ];

            $where = [
                'r.user_id' => $user_id,
                'r.is_deleted' => '0'
            ];

            $data['room'] = $room_model->alias('r')->field($field)->join($join)->where($where)->limit(($page - 1) * $per_page, $per_page)->select();

        }

        return json($this->dataReturn($data));
    }

    public function buildList()
    {
        $data = [];

        if (Request::instance()->isPost()) {
            $user_id = input('post.user_id');
            $per_page = 20;
            $page = input('post.page');

            $build_model = model('Build');

            $where = [
                'user_id' => $user_id,
                'is_deleted' => '0'
            ];

            $data['build'] = $build_model->where($where)->limit(($page - 1) * $per_page, $per_page)->select();
        }

        return json($this->dataReturn($data));
    }
}